home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / objectex / ex27.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  937 b   |  41 lines

  1. Program ex27;
  2.  
  3. { Program to demonstrate the TCollection.Pack method }
  4.  
  5. Uses Objects,MyObject; { For TMyObject definition and registration }
  6.  
  7. Var C : PCollection;
  8.     M : PMyObject;
  9.     I,cnt : Longint;
  10.  
  11. begin
  12.   Randomize;
  13.   C:=New(PCollection,Init(100,10));
  14.   For I:=1 to 100 do
  15.     begin
  16.     M:=New(PMyObject,Init);
  17.     M^.SetField(I-1);
  18.     C^.Insert(M);
  19.     end;
  20.   cnt:=0;
  21.   For I:=0 to 99 do
  22.     begin
  23.     If Random<0.1 then
  24.       begin
  25.       Inc(Cnt);
  26.       C^.FreeItem(C^.At(I));
  27.       C^.AtPut(I,Nil);
  28.       end;
  29.     end;
  30.   Writeln ('Set ',cnt,' pointers to Nil. Count is ',C^.Count);
  31.   Writeln ('Available memory : ',Memavail);
  32.   C^.Pack;
  33.   Writeln ('Packed collection. Count is ',C^.Count);
  34.   cnt:=Memavail;
  35.   Writeln ('Available memory : ',Cnt);
  36.   C^.SetLimit(C^.Count);
  37.   Writeln ('Set limit to ',C^.Count);
  38.   Write   ('Available memory : ',Memavail,'.');
  39.   Writeln (' Gained ',Memavail-cnt,' bytes.');
  40.   Dispose(C,Done);
  41. end.